import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // },

  {
    path: '/main',
    component: Layout,
    redirect: '/main',
    meta: { title: '预览', icon: 'dashboard' },
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/main/index'),
      meta: { title: '业务预览', icon: 'dashboard' }
    }]
  },

  // 404 page must be placed at the end !!!
  //{ path: '*', redirect: '/404', hidden: true }
]

// 异步加载的路由
export const asynRouter = [
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    name: 'order',
    meta: { title: '客户', icon: 'el-icon-s-help', menuNo: 201 },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理', icon: 'table', menuNo: 20101 },
      },
      {
        path: '/order/detail',
        name: 'orderDetail',
        hidden: true,
        component: () => import('@/views/order/detail'),
        meta: { title: '订单详情', icon: 'tree', menuNo: 20102 }
      }
    ]
  },
  {
    path: '/channel',
    component: Layout,
    name: 'channel',
    meta: { title: '预约', icon: 'el-icon-s-help', menuNo: 301 },
    // component:() => import('@/views/information/index'),
    children: [
      {
        path: '/channel/index',
        name: 'channelIndex',
        component: () => import('@/views/channel/index'),
        meta: { title: '渠道管理', icon: 'form', menuNo: 30101 }
      },
    ]
  },
  {
    path: '/product',
    component: Layout,
    meta: { title: '成交', icon: 'el-icon-s-help', menuNo: 401 },
    children: [
      {
        path: '/product/index',
        name: 'product',
        component: () => import('@/views/product/index'),
        meta: { title: '产品管理', icon: 'form', menuNo: 40101 }
      },
      {
        path: '/product/add',
        name: 'addProduct',
        hidden: true,
        component: () => import('@/views/product/add'),
        meta: { title: '新增产品', icon: 'form', menuNo: 40102 }
      },
      {
        path: '/product/edit',
        name: 'editProduct',
        hidden: true,
        component: () => import('@/views/product/edit'),
        meta: { title: '编辑产品', icon: 'form', menuNo: 40103 }
      },
    ]
  },
  {
    path: '/goods',
    component: Layout,
    name: 'goods',
    meta: { title: '排班', icon: 'el-icon-s-help', menuNo: 501 },
    // component:() => import('@/views/information/index'),
    children: [
      {
        path: '/goods/index',
        name: 'goods',
        component: () => import('@/views/goods/index'),
        meta: { title: '商品管理', icon: 'form', menuNo: 50101 }
      },
      {
        path: '/goods/add',
        name: 'addGoods',
        hidden: true,
        component: () => import('@/views/goods/add'),
        meta: { title: '新增商品', icon: 'form', menuNo: 50102 }
      },
      {
        path: '/goods/edit',
        name: 'editGoods',
        hidden: true,
        component: () => import('@/views/goods/edit'),
        meta: { title: '编辑商品', icon: 'form', menuNo: 50103 }
      },
    ]
  },
  {
    path: '/goods',
    component: Layout,
    name: 'goods',
    meta: { title: '医院', icon: 'el-icon-s-help', menuNo: 501 },
    // component:() => import('@/views/information/index'),
    children: [
      {
        path: '/goods/index',
        name: 'goods',
        component: () => import('@/views/goods/index'),
        meta: { title: '商品管理', icon: 'form', menuNo: 50101 }
      },
      {
        path: '/goods/add',
        name: 'addGoods',
        hidden: true,
        component: () => import('@/views/goods/add'),
        meta: { title: '新增商品', icon: 'form', menuNo: 50102 }
      },
      {
        path: '/goods/edit',
        name: 'editGoods',
        hidden: true,
        component: () => import('@/views/goods/edit'),
        meta: { title: '编辑商品', icon: 'form', menuNo: 50103 }
      },
    ]
  },
  {
    path: '/goods',
    component: Layout,
    name: 'goods',
    meta: { title: '数据', icon: 'el-icon-s-help', menuNo: 501 },
    // component:() => import('@/views/information/index'),
    children: [
      {
        path: '/goods/index',
        name: 'goods',
        component: () => import('@/views/goods/index'),
        meta: { title: '商品管理', icon: 'form', menuNo: 50101 }
      },
      {
        path: '/goods/add',
        name: 'addGoods',
        hidden: true,
        component: () => import('@/views/goods/add'),
        meta: { title: '新增商品', icon: 'form', menuNo: 50102 }
      },
      {
        path: '/goods/edit',
        name: 'editGoods',
        hidden: true,
        component: () => import('@/views/goods/edit'),
        meta: { title: '编辑商品', icon: 'form', menuNo: 50103 }
      },
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统', icon: 'el-icon-setting', menuNo: 101 },
    children: [
      {
        path: 'user',
        name: 'systemuser',
        component: () => import('@/views/system/user'),
        meta: { title: '账号管理', icon: 'el-icon-user', menuNo: 10101 }
      },
      {
        path: 'department',
        name: 'department',
        component: () => import('@/views/system/department'),
        meta: { title: '部门管理', icon: 'el-icon-office-building', menuNo: 10102 }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu'),
        meta: { title: '菜单管理', icon: 'el-icon-connection', menuNo: 10103 }
      },
      // {
      //   path: 'permissions',
      //   name: 'permissions',
      //   component: () => import('@/views/system/permissions'),
      //   meta: { title: '权限管理', icon: 'el-icon-connection', menuNo: 10104 }
      // },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role'),
        meta: { title: '角色管理', icon: 'form', menuNo: 10105 }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
